package stack;

import linkedlist.LinkedListStack;
import queue.LoopQueue;
import queue.Queue;

import java.util.Random;

public class StackCompareTest {
    public static void main(String[] args) {
        int opCount = 10000;
        System.out.println("testQueue(new ArrayStack<Integer>,opCount) = " + testStack(new ArrayStack<>(), opCount));
        System.out.println("testQueue(new LinkedListStack<Integer>,opCount) = " + testStack(new LinkedListStack<>(), opCount));
    }

    /**
     * 测试使用q运行opCount个enqueue和dequeue操作所需要的时间，单位：秒
     *
     * @param stack
     * @param opCount
     * @return 秒
     */
    private static double testStack(Stack<Integer> stack, int opCount) {
        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            stack.push(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            stack.pop();
        }
        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }

}
